package com.asiainfo.integration.utils;

import org.apache.log4j.Logger;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.jstl.core.Config;
import java.io.IOException;

public class InitCacheServlet extends HttpServlet {

    private static final long serialVersionUID = -1710300791435113213L;

    private static Logger logger = Logger.getLogger(InitCacheServlet.class);

    public void init(ServletConfig config) throws ServletException {
        try {
            super.init(config);
            ConfigProvider.initialize();
            config.getServletContext().setAttribute("serverIpsMap", ConfigProvider.getServerIpsMap());
        } catch (Exception e) {
            logger.info("Initialing config error", e);
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ConfigProvider.reInitialize();
        request.getRequestDispatcher("/WEB-INF/pages/success.jsp").forward(request, response);
    }
}
